<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
	
	<title>Insert title here</title>
<link href="${project}/ds/css//styles.css" rel="stylesheet" />
    <link href="${project}/ds/css//roomStyle.css" rel="stylesheet"/>
    <link href="${project}/ds/lib//font-awesome-4.7.0/css/font-awesome.css" rel="stylesheet" />
    <link href="${project}/ds/lib//ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" />
    <link href="${project}/ds/lib//ligerUI/skins/Gray2014/css/all.css" rel="stylesheet" />
    <link href="${project}/ds/lib//layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div style="padding:5px;">
<div class="layui-form-item">
    <div class="layui-inline">
        <div id="savebtn" onclick="CheckUrd()" class="layui-btn layui-btn-normal">保存</div>
    </div>
    <div id="grid"></div>
</div>
</div>
<script src="${project}/ds/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="${project}/ds/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="${project}/ds/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${project}/ds/lib/jquery.form.js"></script>
<script src="${project}/ds/lib/layui/layui.js" type="text/javascript"></script>
<script src="${project}/ds/js/XHD.js" type="text/javascript"></script>
<script src="${project}/ds/js/layeralert.js" type="text/javascript"></script>
<script type="text/javascript">
    var manager;
    var layer;
    var user = getCookie("xhdcrm_uid");

    layui.use(['layer'],
        function () {
            layer = layui.layer;
        });
    $(function () {
    	var fileName = decodeURI(getparastr("fileName"));
        manager = $("#grid")
            .ligerGrid({
                columns: [
                    {
                        display: '序号',
                        width: 50,
                        render: function (rowData, rowindex) {
                            return rowindex + 1;
                        }
                    },
                    { display: "姓名", name: "D_Name", width: 60, editor: { type: 'text' } },
                    { display: "性别", name: "D_Sex", width: 40, editor: { type: 'text' } },
                    { display: "手机", name: "D_Tel", width: 110, editor: { type: 'text' } },
                    { display: "身份证", name: "D_Card", width: 160, editor: { type: 'text' } },
                    { display: "置业顾问", name: "D_Saller", width: 80, editor: { type: 'text' } },
                    { display: "置业顾问手机", name: "D_SallerTel", width: 110, editor: { type: 'text' } },
                    { display: "代理机构", name: "D_Proxy", width: 110, editor: { type: 'text' } },
                    { display: "关联人", name: "D_GName", width: 60, editor: { type: 'text' }},
                    { display: "关联人身份证", name: "D_GCardNo", width: 160, editor: { type: 'text' }},
                    { display: "关联人手机", name: "D_GTel", width: 110, editor: { type: 'text' }},
                    { display: "认筹类型", name: "D_FromType", width: 80, editor: { type: 'text' } }
                ],
                dataAction: 'server',
                usePager: false,
                enabledEdit: true,
//                delayLoad: true,
                width: '100%',
                height: '100%',
                heightDiff: -1,
                url:  "/customerOne/readCustomerOneByExcel?fileName="+fileName,
                onRClickToSelect: true
            });
    });

    
    function f_select() {
        var rows = manager.getData();
//            var a = dataValidate(rows);
        if (!dataValidate(rows)) {
            return false;
        }
        return rows;
    }

    function dataValidate(rows) {
        if (rows.length > 0) {
            for (var i in rows) {
                if (rows.hasOwnProperty(i)) {
                    if ($.trim(rows[i].D_Name).length === 0) {
                        layererr("第" + (parseInt(i) + 1) + "行的姓名不能为空");
                        return false;
                    }
                    if ($.trim(rows[i].D_Card).length !== 18
                    ) {
                        layererr("第" + (parseInt(i) + 1) + "行的身份证必须为18位");
                        return false;
                    }
                    if ($.trim(rows[i].D_Tel).length !== 11) {
                        layererr("第" + (parseInt(i) + 1) + "行的手机必须为11位");
                        return false;
                    }
                    if ($.trim(rows[i].D_FromType).length === 0) {
                        layererr("第" + (parseInt(i) + 1) + "行的认筹类型不能为空");
                        return false;
                    }
                }
            }
        } else {
            layererr('无客户数据！');
        }
        return true;
    }

    function CheckUrd() {
        if (f_select()) {
            var rows = manager.getData();
            var postdata = JSON.stringify(rows);

            var index = parent.layer.getFrameIndex(window.name);

            parent.UserSave(postdata, index, 0);
            //parent.CheckUrd(postdata, index, "uploadclientexcel1");
        }
    }

</script>
</body>
</html>
